from typing import TypedDict
import App_setting as setting


class DirectoryItem(TypedDict):
    type: str
    owner: str
    path_name: str
    size: float


hide_path = [
    '/proc', '/boot', '/sys', '/dev',
    '/bin', '/sbin',
    '/lib', '/lib64',
    '/etc',
    ##################################
    '/root'
]


def path_is_valid(path: str) -> bool:
    return __path_is_safe__(path) and __path_is_allow__(path)


def __path_is_safe__(p: str) -> bool:
    """判读目录是不是系统关键目录"""
    for sp in hide_path:
        if p.startswith(sp):
            return False
    return True


def __path_is_allow__(p: str):
    """判断目录是否在配置文件准许里"""
    for item in setting.security.allow_directory_browse:
        if p.startswith(item):
            return True
    return False
